<?php

namespace common\helpers;

use Yii;

/**
 * 自定义实用工具类
 *
 * @author emhome<emhome@163.com>
 * @since 2.0
 */
class ConnerTestHelper {

    /**
     * 内测人员
     * @param integer|array $uid
     * @return type
     */
    public static function isInner() {
        $testUsers = ArrayHelper::getValue(Yii::$app->params, 'developers', []);
        return static::validateLoginUser($testUsers);
    }

    /**
     * 登录用户是否在测试名单中
     * @param integer|array $uid
     * @return type
     */
    public static function validateLoginUser($uid = []) {
        $testUsers = (array) $uid;
        if (empty($testUsers) || Yii::$app->user->isGuest) {
            return false;
        }
        return in_array(Yii::$app->user->id, $testUsers);
    }

    /**
     * 校验测试人员名单
     * @param integer|array $uid
     * @return type
     */
    public static function validateReserver($uid, $list) {
        if (empty($uid) || empty($list)) {
            return false;
        }
        $testers = (array) $list;
        return in_array($uid, $testers);
    }

}
